public class _03 {
/*
来源：力扣（LeetCode）
链接：https://leetcode.cn/problems/find-the-student-that-will-replace-the-chalk/
*/

    public static void main(String[] args) {

    }


    class Solution {
        //循环遍历
        public int chalkReplacer(int[] chalk, int k) {
            long sum = 0;
            for (int t : chalk) {
                sum += t;
            }
            k %= sum;
            for (int i = 0; k >= 0; i++, i %= chalk.length) {
                if (chalk[i] > k) {
                    return i;
                }
                k -= chalk[i];
            }
            return 0;
        }
    }

}

